weiXinController.controller('kgyStoreEditCtl',['$scope','$state','$stateParams','$timeout','$interval','$compile','$rootScope',function($scope,$state,$stateParams,$timeout,$interval,$compile,$rootScope) {
	
	// 测试$scope.$apply使用
	$scope.title = '编辑入库单';
	
	// 显示账外/账内备件 => OUT/IN
	$scope.materiel_account_type = 'OUT';
	
	// 显示冲销/实际备件 => BALANCE/IN
	$scope.materiel_type = 'IN';

	// 账外入库备件列表
	$scope.materiel_out_in_list = [];

	// 账外冲销备件列表
	$scope.materiel_out_balance_list = [];
	
	// 账内入库备件列表
	$scope.materiel_in_in_list = [];

	// 账内冲销备件列表
	$scope.materiel_in_balance_list = [];
	
	// 要编辑的入库单ID
	$scope.editId = '';
	
	// 获取入库单ID
	if($stateParams.param === undefined){
		layer.confirm('参数异常', {
			closeBtn: 0,
			btn: ['返回'],
		}, function(id){
			layer.close(id);
	    	$state.go('/kgy/store/page');
		});
	}else{
		$scope.editId = EdeyeAdmin.unzip($stateParams.param);

		EdeyeAdmin.post({
            url: '/storeInfo/getStoreRecordByStoreId',
            data: {
    			id:$scope.editId
            }
        }, {
            SUCCESS: function (ret) {
            	console.log(ret);
            	$('#type_account').find("option[value='" + ret.storeInfo.type_account + "']").attr("selected",true);
            	$('#type').find("option[value='" + ret.storeInfo.type + "']").attr("selected",true);
            	
            	$scope.materiel_account_type = ret.storeInfo.type_account;
            	$scope.materiel_type = ret.storeInfo.type;

            	var storeInfoRecord = ret.storeInfoRecord;
            	
            	var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
            	
            	for(var tmpKey in storeInfoRecord){
            		var tmpData = storeInfoRecord[tmpKey];
            		
            		var sp_code_filter_data = ret.sp_codes.filter(function(x){
            			return tmpData.sp_code == x.sp_code;
            		});
            		
            		var shelf_filter_data = ret.shelfs.filter(function(x){
            			return tmpData.shelf_id == x.id;
            		});
            		
            		if($scope.materiel_type === 'BALANCE'){
                		var shelf_parent_filter_data = ret.shelfs.filter(function(x){
                			return shelf_filter_data[0].pid == x.id;
                		});
            		}
            		
            		var rifds_filter_data = ret.rfids.filter(function(x){
            			var tmpRfids = JSON.parse(tmpData.rfid);
            			for(var tmpInnerKey in tmpRfids){
            				if(tmpRfids[tmpInnerKey] === x.id){
            					return true;
            				}
            			}
            		});
            		
            		var basket_filter_data = ret.baskets.filter(function(x){
            			return tmpData.device_basket_id == x.id;
            		});
            		
            		var basket_parent_filter_data = ret.baskets.filter(function(x){
            			if(basket_filter_data.length < 1){
            				return false;
            			}
            			return basket_filter_data[0].device_info_id == x.id;
            		});
            		
            		var basket_parent = (basket_parent_filter_data.length > 0 ? ({id:basket_parent_filter_data[0].id,name:basket_parent_filter_data[0].name}) : {});
            		var basket = (basket_filter_data.length > 0 ? ({id:basket_filter_data[0].id,name:basket_filter_data[0].name}) : {});

                	$scope[listName].push({
            			id:tmpData.id,
            			sp_code:tmpData.sp_code,
            			batch_code:tmpData.batch_code,
            			type:tmpData.type,
            			num:parseInt(tmpData.num),
            			unit:sp_code_filter_data[0].unit,
            			cost_center:sp_code_filter_data[0].cost_center,
            			account_number:sp_code_filter_data[0].account_number,
            			type_name:(tmpData.type === 'WEIGHT' ? '称重' : (tmpData.type === 'QR' ? '二维码' : tmpData.type)),
            			shelf_parent:($scope.materiel_type === 'BALANCE' ? {id:shelf_parent_filter_data[0].id,name:shelf_parent_filter_data[0].name} : undefined),
            			shelf:($scope.materiel_type === 'BALANCE' ? {id:shelf_filter_data[0].id,name:shelf_filter_data[0].name} : undefined),
            			rfid:rifds_filter_data,
            			basket_parent:basket_parent,
            			basket:basket,
            			show_rfid:('RFID' === tmpData.type),
            			show_basket:('WEIGHT' === tmpData.type)
            		});
            	}
            	$scope.$apply();
            }
        });
		layer.closeAll();
	}
	
	// 相关说明
	$scope.showDes = function(){
		layer.open({
			type: 1,
			skin: 'layui-layer-rim',
			area: ['420px', '240px'],
			title: '说明',
			content: `
				<div class="row" style="margin-left: 0px; margin-right: 0px; background-color: white;">
					<div class="col-sm-12 mt-3 mb-3">
						入库方式选择冲销:<br />
						实际数量>系统记录数量<br /><br />
						冲销需要在本页绑定相关硬件,<br />
						实际需要在PDA中绑定相关硬件
					</div>
				</div>
				`
		});
	}
	
	// 提交入库单
	$scope.submitStore = function(){
		var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
		if($scope[listName].length < 1){
			EdeyeAdmin.closeMsg('请添加备件',true,1);
			return;
		}
		
		// 冲销校验
		if($scope.materiel_type === 'BALANCE'){
			// RFID备件不可重复绑定
			var rfids = [];
			for(var tmpKey in $scope[listName]){
				if($scope[listName][tmpKey].type === 'RFID'){
					var rfids_ = $scope[listName][tmpKey].rfid;
					for(var tmpInnerKey in rfids_){
						rfids.push(rfids_[tmpInnerKey].id);
					}
				}
			}
			if(rfids.length > 0){
				if((new Set(rfids)).size != rfids.length){
					EdeyeAdmin.closeMsg('有重复绑定的RFID',true,1);
				    return;
				}
			}
		}

        // TODO 二次确认 注释 4月8日
        // layer.confirm('是否提交入库单?', {
			// btn: ['确认','取消'],
			// closeBtn: false
        // }, function(){
			EdeyeAdmin.post({
	            url: '/storeInfo/storeEdit',
	            data: {
	    			id:$scope.editId,
	    			param:$scope[listName]
	            }
	        }, {
	            SUCCESS: function (ret) {
	            	if(ret.code === '200'){
	            		layer.confirm('入库单修改完毕', {
	            			closeBtn: 0,
	            			btn: ['返回'],
	            		}, function(id){
	            			layer.close(id);
	            	    	$state.go('/kgy/store/page');
	            		});
	            	}
	            }
	        });
			layer.closeAll();
		// });
	}
	
	// 切换账外账内显示
	$('#type_account').on('change',function(){
		var type_account_new = $('#type_account').val();
		$scope.$apply(function(){
			$scope.materiel_account_type = type_account_new;
		});
	});
	
	// 准备添加的备件绑定信息(modal中展示)
	$scope.bind_info = {
		sp_code:'',
		batch_code:'',
		type:'',
		unit:'',
		cost_center:'',
		account_number:'',
		num:0,
		shelf_parent:{},
		shelf:{},
		rfid:[],
		rfid_show:'',
		basket_parent:{},
		basket:{},
		show_rfid:false,
		show_basket:false
	}
	
	// 切换入库冲销
	$('#type').on('change',function(){
		var type_account_new = $('#type').val();
		$scope.$apply(function(){
			$scope.materiel_type = type_account_new;
		});	
	});
	
	// 弹出入库单备件新增modal
	$scope.addStoreMaterielModal = function(){
		$('#addStoreMaterielModal').modal({backdrop: 'static', keyboard: false});
	}
	
	// 关闭入库单新增modal
	$scope.closeStoreMaterielModal = function(){
		$scope.bind_info = {
			sp_code:'',
			batch_code:'',
			type:'',
			unit:'',
			cost_center:'',
			account_number:'',
			num:0,
			shelf_parent:{},
			shelf:{},
			rfid:[],
			rfid_show:'',
			basket_parent:{},
			basket:{},
			show_rfid:false,
			show_basket:false
		}
		$('#addStoreMaterielModal').modal('hide');
	}
	
	// 新增入库单备件并关闭modal
	$scope.addStoreMateriel = function(){
		// 实际/冲销校验SP号,批次号,新增数量
        var ret = EdeyeAdmin.checkKit.finalCheck($scope.bind_info, true, {
            'sp_code': {
                method: 'strRange',
                methodParam: ['&&', ['>=', 1], ['<=', 128]],
                msg: '请选择CP号'
            },
            'batch_code': {
                method: 'strRange',
                methodParam: ['&&', ['>=', 1], ['<=', 128]],
                msg: '批次号长度在1~128之间'
            },
            'num': {
                method: 'integerRange',
                methodParam: ['&&', ['>=', 1], ['<=', 1000000]],
                msg: '新增数量在1~1000000'
            }
        });
        if (!ret.flag) {
            EdeyeAdmin.closeMsg(ret.msg.join('<br />'), false, 1);
            return;
        }
		
		if($scope.materiel_type === 'BALANCE'){
			// 冲销入库校验是否选择货位
			if($scope.bind_info.shelf.id === undefined){
				EdeyeAdmin.closeMsg('请选择货位',true,1);
				return;
			}
			
			// RFID
			if($scope.bind_info.type === 'RFID'){
				if($scope.bind_info.rfid.length < 1){
					EdeyeAdmin.closeMsg('请选择RFID标签',true,1);
					return;
				}
				if($scope.bind_info.rfid.length != $scope.bind_info.num){
					EdeyeAdmin.closeMsg('已选择的RFID标签个数与新增数量不符',true,1);
					return;
				}
				var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
				for(var tmpKey in $scope[listName]){
					if($scope[listName][tmpKey].type === 'RFID'){
						var addedRfids = $scope[listName][tmpKey].rfid;
						for(var tmpInnerKey in addedRfids){
							for(var tmpInInnerKey in $scope.bind_info.rfid){
								if(addedRfids[tmpInnerKey].id === $scope.bind_info.rfid[tmpInInnerKey].id){
									EdeyeAdmin.closeMsg('RFID标签已被其他备件选中，请重新选择',true,1);
									return;
								}
							}
						}
					}
				}
			}
			
			// WEIGHT
			if($scope.bind_info.type === 'WEIGHT'){
				if($scope.bind_info.basket.id === undefined){
					EdeyeAdmin.closeMsg('请选择称重筐',true,1);
					return;
				}
				var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
				for(var tmpKey in $scope[listName]){
					if($scope[listName][tmpKey].type === 'WEIGHT'){
						if($scope[listName][tmpKey].sp_code !== $scope.bind_info.sp_code && $scope[listName][tmpKey].basket.id === $scope.bind_info.basket.id){
							EdeyeAdmin.closeMsg('物料盒已被其他备件选中，请重新选择',true,1);
							return;
						}
					}
				}
			}
		}
		
		var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
		$scope[listName].push({
			id:moment().format('YYMMDDHHmmssSSS'),
			sp_code:$scope.bind_info.sp_code,
			batch_code:$scope.bind_info.batch_code,
			type:$scope.bind_info.type,
			num:$scope.bind_info.num,
			unit:$scope.bind_info.unit,
			cost_center:$scope.bind_info.cost_center,
			account_number:$scope.bind_info.account_number,
			type_name:($scope.bind_info.type === 'WEIGHT' ? '称重' : ($scope.bind_info.type === 'QR' ? '二维码' : $scope.bind_info.type)),
			shelf_parent:$scope.bind_info.shelf_parent,
			shelf:$scope.bind_info.shelf,
			rfid:$scope.bind_info.rfid,
			basket_parent:$scope.bind_info.basket_parent,
			basket:$scope.bind_info.basket
		});
		
		$scope.closeStoreMaterielModal();
	}
	
	// 已加入到入库单中的备件查看时的ng1对象
	$scope.materielViewObj = {};
	
	// 查看加入到入库单中的备件详情
	$scope.viewStoreMateriel = function(id){
		
		var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
		for(var tmpKey in $scope[listName]){
			if($scope[listName][tmpKey].id === id){
				$scope.materielViewObj = $scope[listName][tmpKey];
				break;
			}
		}
		if($scope.materielViewObj.rfid.length > 0){
			$scope.materielViewObj.show_rfid = true;
			$scope.materielViewObj.show_basket = false;
			
			for(var tmpKey in $scope.materielViewObj.rfid){
				if(tmpKey === '0'){
					$scope.materielViewObj.rfid_show = $scope.materielViewObj.rfid[tmpKey].name;
				}else{
					$scope.materielViewObj.rfid_show += ' | ' + $scope.materielViewObj.rfid[tmpKey].name;
				}
			}
		}
		if($scope.materielViewObj.basket.id !== undefined){
			$scope.materielViewObj.show_basket = true;
			$scope.materielViewObj.show_rfid = false;
		}
		
		$('#viewMaterielModal').modal('show');
	}
	
	// 移出加入到入库单中的备件
	$scope.removeStoreMateriel = function(id){
        // TODO 二次确认 注释 4月8日
        // layer.confirm('是否将备件从列表中移出?', {
			// btn: ['确认','取消'],
			// closeBtn: false
        // }, function(){
			var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
			for(var tmpKey in $scope[listName]){
				if($scope[listName][tmpKey].id === id){
					// $scope.$apply(function(){
						$scope[listName].splice(tmpKey, 1);
					// });
					break;
				}
			}
			layer.closeAll();
		// }, function(){
		// });
	}
	
	// 弹出SP号的modal
	$scope.openSelectSpModal = function(){
		$scope.spPageSearch();
		$('#selectSpModal').modal('show');
	}
	
	// 选择SP号后数据回填,并关闭modal
	$scope.callBackSelectSpModal = function(data){
		console.log($scope.materiel_type);
		// 第1次选择时,不弹出更换提示
		if($scope.bind_info.sp_code.length < 1 || $scope.materiel_type === 'IN'){
			$scope.$apply(function(){
				$scope.bind_info.sp_code = data.sp_code;
				$scope.bind_info.type = data.type;
				if($scope.bind_info.type === 'WEIGHT'){
					$scope.bind_info.type_view = '称重';
					$scope.bind_info.show_rfid = false;
					$scope.bind_info.show_basket = true;
				}
				if($scope.bind_info.type === 'QR'){
					$scope.bind_info.type_view = '二维码';
					$scope.bind_info.show_rfid = false;
					$scope.bind_info.show_basket = false;
				}
				if($scope.bind_info.type === 'RFID'){
					$scope.bind_info.type_view = data.type;
					$scope.bind_info.show_rfid = true;
					$scope.bind_info.show_basket = false;
				}
				if($scope.materiel_type === 'IN'){
					$scope.bind_info.show_rfid = false;
					$scope.bind_info.show_basket = false;
				}
				
				$scope.bind_info.batch_code = '';
				$scope.bind_info.unit = data.unit;
				$scope.bind_info.cost_center = data.cost_center;
				$scope.bind_info.account_number = data.account_number;

				$scope.bind_info.shelf = {};
				$scope.bind_info.shelf_parent = {};
				
				$scope.bind_info.rfid = [];
				$scope.bind_info.rfid_show = '';
				
				$scope.bind_info.basket_parent = {};
				$scope.bind_info.basket = {};
			});
			$('#selectSpModal').modal('hide');
			return;
		}
        // TODO 二次确认 注释 4月8日
        // layer.confirm('更换SP号后将会重新绑定', {
			// btn: ['更换','不更换']
        // }, function(){
			$scope.$apply(function(){
				$scope.bind_info.sp_code = data.sp_code;
				$scope.bind_info.type = data.type;
				if($scope.bind_info.type === 'WEIGHT'){
					$scope.bind_info.type_view = '称重';
					$scope.bind_info.show_rfid = false;
					$scope.bind_info.show_basket = true;
				}
				if($scope.bind_info.type === 'QR'){
					$scope.bind_info.type_view = '二维码';
					$scope.bind_info.show_rfid = false;
					$scope.bind_info.show_basket = false;
				}
				if($scope.bind_info.type === 'RFID'){
					$scope.bind_info.type_view = data.type;
					$scope.bind_info.show_rfid = true;
					$scope.bind_info.show_basket = false;
				}
				if($scope.materiel_type === 'IN'){
					$scope.bind_info.show_rfid = false;
					$scope.bind_info.show_basket = false;
				}
				
				$scope.bind_info.batch_code = '';
				$scope.bind_info.unit = data.unit;
				$scope.bind_info.cost_center = data.cost_center;
				$scope.bind_info.account_number = data.account_number;

				$scope.bind_info.shelf = {};
				$scope.bind_info.shelf_parent = {};
				
				$scope.bind_info.rfid = [];
				$scope.bind_info.rfid_show = '';
				
				$scope.bind_info.basket_parent = {};
				$scope.bind_info.basket = {};
			});
			layer.closeAll();
		// });
		$('#selectSpModal').modal('hide');
	}
	
	// 弹出批次号号的modal
	$scope.openSelectBatchModal = function(){
		if($scope.bind_info.sp_code.length < 1){
			EdeyeAdmin.closeMsg('请先选择CP号',true,1);
			return;
		}
		$scope.batchPageSearch();
		$('#selectBatchModal').modal('show');
	}
	
	// 选择批次号号后数据回填,并关闭modal
	$scope.callBackSelectBatchModal = function(data){
		$scope.$apply(function(){
			$scope.bind_info.batch_code = data.batch_code;
		});
		$('#selectBatchModal').modal('hide');
	}
	
	// 货架货位树形配置
	var shelfTreeConfig = {
        treeId: 'shelfTree',
        view: {
            showLine: true,
            selectedMulti: false,
            dblClickExpand: false,
            addDiyDom: function (treeId, treeNode) {
                var aObj = $("#" + treeNode.tId + '_a');
                var msg = (treeNode.level === 0 ? '货架' : '货位');
                aObj.append('<span>[' + msg + ']</span>');
            }
        },
        data: {
            simpleData: {
                enable: true,
                idKey: 'id',
                pIdKey: 'pid'
            }
        },
        edit: {
            enable: false
        },
        check: {
            enable: false
        }
    };
    var shelfTree = null;
	
	// 弹出选择货位的modal
	$scope.openSelectShelfModal = function(){
		if($scope.bind_info.sp_code.length < 1){
			EdeyeAdmin.closeMsg('请先选择CP号',true,1);
			return;
		}

		shelfTree = $.fn.zTree.init($("#shelfTree"), shelfTreeConfig);
		
		var postData = {materiel_account_type:$scope.materiel_account_type,sp_code:$scope.bind_info.sp_code};
        EdeyeAdmin.post({
            url: '/storeInfo/getAllShelfTreeData',
            data: postData
        }, {
            SUCCESS: function (ret) {
        		shelfTree.addNodes(null, ret.data);
                setTimeout(function () {
                	shelfTree.expandAll(true);
                }, 200);

        		$('#selectShelfModal').modal('show');
            }
        });
	}

	// 选择货位后回调方法
	$scope.callBackSelectShelfModal = function(){
		var nodes = shelfTree.getSelectedNodes();
		if(nodes.length < 1){
			EdeyeAdmin.closeMsg('请选择货位',true,1);
			return;
		}
		if(nodes[0].level === 0){
			EdeyeAdmin.closeMsg('请选择货位',true,1);
			return;
		}
		
		$scope.bind_info.shelf.id = nodes[0].id;
		$scope.bind_info.shelf.name = nodes[0].name;
		$scope.bind_info.shelf_parent.id = nodes[0].getParentNode().id;
		$scope.bind_info.shelf_parent.name = nodes[0].getParentNode().name;

		$scope.bind_info.rfid = [];
		$scope.bind_info.rfid_show = '';

		$('#selectShelfModal').modal('hide');
	}
	
	// 弹出选择rfid标签的modal
	$scope.openSelectRfidModal = function(){
		if($scope.bind_info.shelf.id === undefined){
			EdeyeAdmin.closeMsg('请先选择货位',true,1);
			return;
		}
		$scope.rfidPageSearch();
		$('#selectRfidModal').modal('show');
	}
	
	// 选择rfid标签后回调的方法
	$scope.callBackSelectRfidModal = function(){
		var selectData = EdeyeAdmin.getDataTableSelectPhone('rfidTable');
		if(selectData.length < 1){
			EdeyeAdmin.closeMsg('请选择RFID标签',true,1);
			return;
		}
		
		$scope.bind_info.rfid = selectData;
		for(var tmpKey in selectData){
			if(tmpKey === '0'){
				$scope.bind_info.rfid_show = selectData[tmpKey].name;
			}else{
				$scope.bind_info.rfid_show += ' | ' + selectData[tmpKey].name;
			}
		}
		
		$('#selectRfidModal').modal('hide');
	}

	// 称,物料盒树形配置
	var weighTreeConfig = {
        treeId: 'weighTree',
        view: {
            showLine: true,
            selectedMulti: false,
            dblClickExpand: false,
            addDiyDom: function (treeId, treeNode) {
                var aObj = $("#" + treeNode.tId + '_a');
                var msg = (treeNode.level === 0 ? '称' : '物料盒');
                aObj.append('<span>[' + msg + ']</span>');
            }
        },
        data: {
            simpleData: {
                enable: true,
                idKey: 'id',
                pIdKey: 'pid'
            }
        },
        edit: {
            enable: false
        },
        check: {
            enable: false
        }
    };
	var weighTree = null;
	
	// 弹出选择物料盒的modal
	$scope.openSelectBasketModal = function(){
		if($scope.bind_info.shelf.id === undefined){
			EdeyeAdmin.closeMsg('请先选择货位',true,1);
			return;
		}

		weighTree = $.fn.zTree.init($("#weighTree"), weighTreeConfig);
		
        EdeyeAdmin.post({
            url: '/storeInfo/getAllWeightTreeData',
            data: {sp_code:$scope.bind_info.sp_code,type_account:$('#type_account').val(),shelf_id:$scope.bind_info.shelf.id}
        }, {
            SUCCESS: function (ret) {
            	weighTree.addNodes(null, ret.data);
                setTimeout(function () {
                	weighTree.expandAll(true);
                }, 200);

        		$('#selectBasketModal').modal('show');
            }
        });
	}
	
	// 选择物料盒后回调方法
	$scope.callBackSelectBasketModal = function(){
		var nodes = weighTree.getSelectedNodes();
		if(nodes.length < 1){
			EdeyeAdmin.closeMsg('请选择物料盒',true,1);
			return;
		}
		if(nodes[0].level === 0){
			EdeyeAdmin.closeMsg('请选择物料盒',true,1);
			return;
		}

		$scope.bind_info.basket.id = nodes[0].id;
		$scope.bind_info.basket.name = nodes[0].name;
		$scope.bind_info.basket_parent.id = nodes[0].getParentNode().id;
		$scope.bind_info.basket_parent.name = nodes[0].getParentNode().name;

		$('#selectBasketModal').modal('hide');
	}

	// 多层modal必须使用这个方法,否则会造成上1层的modal失去滚动条
	$('#selectSpModal,#selectBatchModal,#selectShelfModal,#selectRfidModal,#selectBasketModal').on('hidden.bs.modal', function (event) {
		$("body").addClass("modal-open");
	});
	
	// SP号分页初始化条件
	var spPageParam = {
		id : 'spTable',
		checkbox:false,
		column : [
			{
				type:'rowNum',
				title:'编号',
			},{
				type:'key',
				mapping:'id',
				show:false
			},{
				mapping:'name',
				title:'名称',
				show:false
			},{
				mapping:'unit',
				title:'单位',
				show:false
			},{
				mapping:'sp_code',
				title:'CP编号'
			},{
				mapping:'cost_center',
				title:'成本中心',
				show:false
			},{
				mapping:'account_number',
				title:'科目号',
				show:false
			},{
				mapping:'type',
				title:'分类类型',
				trans : function(data){
					if(data.type == 'WEIGHT') {
						return "称重";
					} else if(data.type == 'QR') {
						return "二维码";
					}
					return data.type;
				}
			},{
				mapping:'borrow',
				title:'能否借用',
                trans:function(data){
                	if(data.borrow === 'CAN'){
                		return '可以借用';
                	}
                	if(data.borrow === 'CANT'){
                		return '不可借用';
                	}
                }
			},{
                type: 'function',
                title: '操作',
                titleDivStyle: 'text-align: center',
                dataDivStyle: 'text-align: center',
                func: [{
                    title: '选择',
                    css: 'btn-sm btn-outline-info',
                    text111: '<i class="fas fa-check"></i>',
                    text: '选择',
                    func: function (data) {
                        $scope.callBackSelectSpModal(data);
                    }
                }]
            }
		],
		pageConfig:{
			showGoNum:false
		},
		pageSize:[[5],10,50,100],
		page:function(cmd, currentPage, pageSize, totalPageNum){
			if('first' === cmd){
				currentPage = 1;
			}else if('prev' === cmd){
				currentPage--;
			}else if('next' === cmd){
				currentPage++;
			}else if('last' === cmd){
				currentPage = totalPageNum;
			}else if('change' === cmd){
				currentPage = 1;
			}
			$scope.spPageSearch(currentPage,pageSize);
		}
	};
	EdeyeAdmin.initDataTablePhone(spPageParam, {data:[]});
	
	$scope.spPageSearch = function(currentPage,pageSize){
		var postData = {materiel_account_type:$scope.materiel_account_type};
		postData.currentPage = (currentPage === undefined ? 1 : currentPage);
		postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(spPageParam.id) : pageSize);
		EdeyeAdmin.post({
			url:'/storeInfo/getAllMaterielPage',
			data:postData
		},{
			SUCCESS:function(ret){
				if(ret.code === '200'){
            		$scope.prefix = ret.prefix;
					EdeyeAdmin.setDataTableDataPhone(spPageParam, ret.data);
				}
			}
		});
	}
	
	// 批次号分页初始化条件
	var batchPageParam = {
		id : 'batchTable',
		checkbox:false,
		column : [
			{
				type:'rowNum',
				title:'编号',
			},{
				type:'key',
				mapping:'id',
				show:false
			},{
				mapping:'batch_code',
				title:'批次号'
			},{
                type: 'function',
                title: '操作',
                titleDivStyle: 'text-align: center',
                dataDivStyle: 'text-align: center',
                func: [{
                    title: '选择',
                    css: 'btn-sm btn-outline-info',
                    text111: '<i class="fas fa-check"></i>',
                    text: '选择',
                    func: function (data) {
                        $scope.callBackSelectBatchModal(data);
                    }
                }]
            }
		],
		pageConfig:{
			showGoNum:false
		},
		pageSize:[[5],10,50,100],
		page:function(cmd, currentPage, pageSize, totalPageNum){
			if('first' === cmd){
				currentPage = 1;
			}else if('prev' === cmd){
				currentPage--;
			}else if('next' === cmd){
				currentPage++;
			}else if('last' === cmd){
				currentPage = totalPageNum;
			}else if('change' === cmd){
				currentPage = 1;
			}
			$scope.batchPageSearch(currentPage,pageSize);
		}
	};
	EdeyeAdmin.initDataTablePhone(batchPageParam, {data:[]});
	
	$scope.batchPageSearch = function(currentPage,pageSize){
		var postData = {materiel_account_type:$scope.materiel_account_type,sp_code:$scope.bind_info.sp_code};
		postData.currentPage = (currentPage === undefined ? 1 : currentPage);
		postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(batchPageParam.id) : pageSize);
		EdeyeAdmin.post({
			url:'/storeInfo/getAllMaterielTypeStockPage',
			data:postData
		},{
			SUCCESS:function(ret){
				if(ret.code === '200'){
            		$scope.prefix = ret.prefix;
					EdeyeAdmin.setDataTableDataPhone(batchPageParam, ret.data);
				}
			}
		});
	}
	
	// RFID分页初始化条件
	var rfidPageParam = {
		id : 'rfidTable',
		column : [
			{
				type:'rowNum',
				title:'编号',
			},{
				type:'key',
				mapping:'id',
				show:false
			},{
				mapping:'name',
				title:'名称'
			},{
				mapping:'code',
				title:'编码'
            }
		],
		pageConfig:{
			showGoNum:false
		},
		pageSize:[[5],10,50,100,1000],
		page:function(cmd, currentPage, pageSize, totalPageNum){
			if('first' === cmd){
				currentPage = 1;
			}else if('prev' === cmd){
				currentPage--;
			}else if('next' === cmd){
				currentPage++;
			}else if('last' === cmd){
				currentPage = totalPageNum;
			}else if('change' === cmd){
				currentPage = 1;
			}
			$scope.rfidPageSearch(currentPage,pageSize);
		}
	};
	EdeyeAdmin.initDataTablePhone(rfidPageParam, {data:[]});
	
	$scope.rfidPageSearch = function(currentPage,pageSize){
		var postData = {};
		postData.currentPage = (currentPage === undefined ? 1 : currentPage);
		postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(rfidPageParam.id) : pageSize);
		EdeyeAdmin.post({
			url:'/storeInfo/getAllRfidPage',
			data:postData
		},{
			SUCCESS:function(ret){
				if(ret.code === '200'){
            		$scope.prefix = ret.prefix;
					EdeyeAdmin.setDataTableDataPhone(rfidPageParam, ret.data);
				}
			}
		});
	}
	
}]);